package thread;
class MyThread extends Thread {
    @Override
    public void run() {
        //这里写的代码,是即将创建好的线程要执行的逻辑
        while(true) {
            System.out.println("hello thread");
            //在循环中加一个休眠操作,让程序每次循环之后都休息一会
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
//                throw new RuntimeException(e);
                e.printStackTrace();
            }
        }
    }
}
public class Demo1 {
    public static void main(String[] args) {
        MyThread myThread = new MyThread();
        myThread.start();
//        myThread.run();//若直接调用run,则是在主线程执行,不会创建新线程
        while(true) {
            System.out.println("hello main");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
//                throw new RuntimeException(e);
                e.printStackTrace();
            }
        }
    }
}
